<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php
$attributes = array(
    'class' => 'control-label',
);

?>

<div class="span9">

    <?php echo get_message(); ?>

    <h2><?php echo $titulo; ?></h2>

    <?php echo form_open(); ?>

    <h3>Buscar:</h3>
    <div class="row-fluid">
        <div class="span3">
            <?php echo form_label('Fecha desde', 'fechaDesde', $attributes); ?>
            <div class="controls input-append">
                <?php
                echo form_input(array('class' => 'span11 date-picker', 'data-date-format' => 'dd/mm/yyyy', 'name' => 'fechaDesde', 'type' => 'text', 'value' => $busqueda['fechaDesde']));
                ?><span class="add-on"><i class="icon-calendar"></i></span>
            </div>
        </div>
        <div class="span3">
            <?php echo form_label('Fecha hasta', 'fechaHasta', $attributes); ?>
            <div class="controls input-append">
                <?php
                echo form_input(array('class' => 'span11 date-picker', 'data-date-format' => 'dd/mm/yyyy', 'name' => 'fechaHasta', 'type' => 'text', 'value' => $busqueda['fechaHasta']));
                ?><span class="add-on"><i class="icon-calendar"></i></span>
            </div>
        </div>
        <div class="span3">
            <div class="control-group">
                <?php echo form_label('&nbsp;', ' ', $attributes); ?>
                <div class="controls">
                    <?php echo form_input(array('class' => 'span11', 'name' => 'submit', 'type' => 'submit', 'value' => 'Buscar', 'class' => 'btn')); ?>
                </div>
            </div>
        </div>
    </div>

    <?php echo form_close(); ?>

    <div class="container-table">
        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-hover table-bordered" id="example">
            <thead>
                <tr>
                    <th>Fecha</th>
                    <th>Importe</th>
                    <th>Nro Cpte Pago</th>
                    <th>Nro Cheque</th>
                    <th>Banco</th>
                    <th>Concepto</th>
                    <th>Beneficiario</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (!empty($ultimos_pagos)) {
                    $color = 'odd';
                    foreach ($ultimos_pagos as $pago) {
                        $color = ( $color == 'odd') ? 'even' : 'odd';
                        ?>
                        <tr class="<?php echo $color; ?>">
                            <td><?php echo database_to_normal_date($pago->fecha); ?></td>
                            <td><?php echo $pago->moneda . $pago->importe; ?></td>
                            <td><?php echo $pago->nroCptePago; ?></td>
                            <td><?php echo $pago->nroCheque; ?></td>
                            <td><?php echo $pago->banco . ' - ' . $pago->sucursal . ' (' . $pago->nroCuenta . ')'; ?></td>
                            <td><?php echo $pago->concepto; ?></td>
                            <td><?php echo $pago->beneficiario; ?></td>
                            <td>
                                <a class="btn btn-small" href="javascript:detalle('<?php echo $pago->id; ?>')"><span class="icon-list-alt"></span> Detalle</a>
                                <?php if(isset($cancelar)) { ?>
                                <a class="btn btn-small cancelar" href="#cancelar" role="button" data-toggle="modal" dbid="<?php echo $pago->id; ?>"><span class="icon-remove"></span> Cancelar</a>
                                <?php } ?>
                            </td>
                        </tr>
                        <?php
                    }
                }
                ?>
            </tbody>
        </table>
    </div>
</div>

<?php echo form_hidden('idPago', ''); ?>

<script type="text/javascript">
    var popup;
    function detalle(id){
        popup = window.open("<?php echo base_url('subsidios/detalle'); ?>/" + id,"miwin","left=200,top=50,width=800,height=500,scrollbars=yes");
        popup.focus();
    }
    
    $('#confirmacancelacion').live('click', function(){
        window.location = "<?php echo base_url('subsidios/cancelar'); ?>/" + $('input[name="idPago"]').val();
    });
    $('.cancelar').live('click', function(){
        $('input[name=idPago]').val($(this).attr('dbid'));
    });
</script>

<div class="modal toggle fade" id="cancelar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Cancelar Pago</h3>
    </div>
    <div class="modal-body">
        <p>¿Está seguro?</p>
    </div>
    <div class="modal-footer">       
        <button id="confirmacancelacion" class="btn btn-primary">Si</button>
        <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
    </div>
</div>